package main

import (
	"log"
	"net/http"
	"os"

	"github.com/kubeflow/kronos-server/api/handler"
)

func main() {
	log.SetOutput(os.Stdout)

	session, err := handler.InitMongoDb()
	if err != nil {
		log.Fatalf("Failed to connect mongoDB: %v", err)
	}
	defer session.Close()

	apiHandler, err := handler.CreateHTTPAPIHandler(session)
	if err != nil {
		log.Fatalf("Error while creating the API Handler: %v", err)
	}

	http.Handle("/kronos/api/", apiHandler)

	p := ":8080"
	log.Println("Rest api available at /kronos/api/ on port", p)

	if err = http.ListenAndServe(p, nil); err != nil {
		log.Fatalf("Failed to serve: %v", err)
	}
}
